Page({
    data: {
      list: [],          // 活动列表
      showToast: false  // 控制弹窗
    },
  
    onLoad() {
      // 模拟接口返回
      const raw = [
        { id: 1, title: '夏日观影会', time: '7月15日 19:00', pic: 'https://picsum.photos/200?random=1' },
        { id: 2, title: '手冲咖啡体验', time: '7月20日 14:00', pic: 'https://picsum.photos/200?random=2' },
        { id: 3, title: '城市夜跑', time: '7月22日 20:00', pic: 'https://picsum.photos/200?random=3' }
      ];
  
      // 读取本地缓存的预约状态
      const bookedMap = wx.getStorageSync('bookedMap') || {};
      const list = raw.map(item => ({
        ...item,
        booked: !!bookedMap[item.id]
      }));
  
      this.setData({ list });
    },
  
    // 点击预约
    onBook(e) {
      const id = e.currentTarget.dataset.id;
      const list = this.data.list.map(item =>
        item.id === id ? { ...item, booked: true } : item
      );
  
      // 更新本地缓存
      const bookedMap = wx.getStorageSync('bookedMap') || {};
      bookedMap[id] = true;
      wx.setStorageSync('bookedMap', bookedMap);
  
      this.setData({ list, showToast: true });
    },
  
    // 关闭弹窗
    closeToast() {
      this.setData({ showToast: false });
    }
  });